public class test2 {
    //力扣 918.环形子数组的最大和
    public int maxSubarraySumCircular(int[] nums) {
        //创建dp表
        //初始化
        //填表
        //返回值
        int n = nums.length;
        int[] dpmax = new int[n+1];
        int[] dpmin = new int[n+1];
        int sum = 0;
        int max = Integer.MIN_VALUE;
        int min = Integer.MAX_VALUE;
        for(int i = 1;i<n+1;i++){
            int x = nums[i-1];
            dpmax[i] = Math.max(x,dpmax[i-1] + x);
            max = Math.max(dpmax[i],max);
            dpmin[i] = Math.min(x,dpmin[i-1] + x);
            min = Math.min(dpmin[i],min);
            sum+=x;
        }
        return sum==min? max : Math.max(max,sum-min);
    }
}
